<div class="row">
	<div class="col-xs-12">
		<div class="box">
			<div class="box-header">
				<h3 class="box-title">日志管理</h3>
				<div class="box-tools">
					<div class="input-group input-group-sm" style="width: 350px;">
						<input type="text" name="table_search" id="searchNameId"
							class="form-control pull-right" placeholder="用户名">

						<div class="input-group-btn">
							<button type="button" class="btn btn-default btn-search">
                                <i class="fa fa-search"></i>
							</button>
							<button type="button" class="btn btn-default btn-delete">删除</button>
						</div>
					</div>
				</div>
			</div>
			<!-- /.box-header -->
			<div class="box-body table-responsive no-padding">
				<table class="table table-hover">
					<thead>
						<tr>
						    <th><input type="checkbox" id="checkAll">全选</th>
							<th>用户名</th>
							<th>操作</th>
							<th>请求方法</th>
							<th>请求参数</th>
							<th>IP</th>
							<th>执行时长</th>
						</tr>
					</thead>
					<tbody id="tbodyId">
					    <tr>
					       <td colspan="7">数据正在加载中...</td>
					    </tr>
					</tbody>
				</table>
			</div>
			<div id="pageId" class="box-footer clearfix" dm="100">
			  
			</div>
			<!-- /.box-body -->
		</div>
		<!-- /.box -->
	</div>
</div>
<script type="text/javascript">

	var userName='';
	$(function (){
		$("#pageId").load("doPageUI");
		$("#checkAll").change(doCheckAll);
		$("#tbodyId").on("change",".idcheckbox",doChangeCheckAll);
	});

	function doChangeCheckAll(){
		let type=true;
		let deletetype=false;
		$("#tbodyId input[type='checkbox']").each(function (){
			deletetype=deletetype||$(this).prop("checked");
			type=type&&$(this).prop("checked");
		});
		$("#checkAll").prop("checked",type);
		$(".btn-delete").prop("disabled",!deletetype);
	}

	function doCheckAll(){
		$("#tbodyId input[type='checkbox']").prop("checked",$(this).prop("checked"));
		$(".btn-delete").prop("disabled",!$(this).prop("checked"));
	}

	function getPageObject(){
		debugger;
		$("#checkAll").prop("checked",false);
		$(".btn-delete").prop("disabled",true);
		var url="getPageObject";
		var params={
			"username":userName,
			"currentPage": $(".pagination").data("pageCurrent")
		};
		$.getJSON(url,params,function (res){
			if(res.state==1){
			addTags(res.data.records);
			setPageObject(res.data);
			}else {
				$("#tbodyId").html(res.message);
			}
		});
	}
	function addTags(Object){
		var tbody=$("#tbodyId");
		tbody.empty();
		for(var i in Object){
			var tr=$("<tr></tr>");
			var tds=createdTd(Object[i]);
			tr.append(tds);
			tbody.append(tr);
		}
	}
	function createdTd(object){

		var tds="<td><input type='checkbox' class='idcheckbox' value='"+object.id+"'>"+object.id+"</td>"+
				"<td>"+object.username+"</td>"+
				"<td>"+object.operation+"</td>"+
		"<td>"+object.method+"</td>"+
		"<td>"+object.params+"</td>"+
		"<td>"+object.ip+"</td>"+
		"<td>"+object.time+"</td>";
		return tds;
	}

	$(".input-group-btn").on("click",".btn-search",getPageObjectByName)
	.on("click",".btn-delete",doDeleteObject);

	function getPageObjectByName(){
		userName=$("#searchNameId").val();
		$(".pagination").data("pageCurrent",1);
		getPageObject();
	}

	function doDeleteObject(){
		debugger;
		let ids=[];
		$("#tbodyId input[type=checkbox]:checked").each(function (){
			ids.push( $(this).val());
		})
		let params={"ids":ids.toString()};
		let url="deleteById";
		$.getJSON(url,params,function (res){
			if(res.state==1){
				debugger;
				window.alert(res.message);
				var type=$("#checkAll").prop("checked");
				if(type){
					doAfterDelete();
				}
				getPageObject();
			}else {
				window.alert(res.message);
			}
		});
	}
	function doAfterDelete(){
		debugger;
		let pageCurrent=$(".pagination").data("pageCurrent");
		let pageCount=$(".pagination").data("pageCount");
		if(pageCurrent==pageCount&&pageCurrent>1){
			pageCurrent--;
			pageCount--;
			$(".pagination").data("pageCurrent",pageCurrent);
			$(".pagination").data("pageCount",pageCount);
		}
	}




</script>






